# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Callan Barrett <wizzomafizzo@gmail.com>
# Contributor: mucknert <mucknert@gmx.net>

pkgname=offlineimap
_pkgname=${pkgname}3
pkgver=8.0.0
pkgrel=4
pkgdesc='Synchronizes emails between two repositories'
arch=('any')
url='http://offlineimap.org/'
license=('GPL')
depends=('python-imaplib2' 'python-distro' 'python-rfc6555')
makedepends=('asciidoc')
optdepends=(
    "python-gssapi: for Kerberos authentication"
    "python-pysocks: for SOCKS5 proxy functionality")
source=($pkgname-$pkgver.tar.gz::https://github.com/OfflineIMAP/offlineimap3/archive/v${pkgver}.tar.gz
"$pkgname-$pkgver-py311.patch::https://github.com/OfflineIMAP/offlineimap3/commit/7cd32cf834b34a3d4675b29bebcd32dc1e5ef128.patch"
)
sha256sums=('5d40c163ca2fbf89658116e29f8fa75050d0c34c29619019eee1a84c90fcab32'
            '204a900b0854afaca85b0f0a8da4bd31c4b702103a8f315cd553c53c60be4ac2')

prepare() {
  cd "${_pkgname}-${pkgver}"
  patch -Np1 < "$srcdir/offlineimap-8.0.0-py311.patch"
}

build() {
  cd ${_pkgname}-${pkgver}
  python setup.py build
  make -C docs man
}

package() {
  cd ${_pkgname}-${pkgver}

  python setup.py install --root="${pkgdir}" --optimize=1
  install -Dm644 docs/offlineimap.1 "${pkgdir}"/usr/share/man/man1/offlineimap.1
  install -Dm644 docs/offlineimapui.7 "${pkgdir}"/usr/share/man/man7/offlineimapui.7
  install -Dm644 offlineimap.conf "${pkgdir}"/usr/share/offlineimap/offlineimap.conf
  install -Dm644 offlineimap.conf.minimal "${pkgdir}"/usr/share/offlineimap/offlineimap.conf.minimal

  install -Dm644 contrib/systemd/$pkgname.service "${pkgdir}"/usr/lib/systemd/user/$pkgname.service
  install -Dm644 contrib/systemd/$pkgname@.service "${pkgdir}"/usr/lib/systemd/user/$pkgname@.service
  install -Dm644 contrib/systemd/$pkgname-oneshot.service "${pkgdir}"/usr/lib/systemd/user/$pkgname-oneshot.service
  install -Dm644 contrib/systemd/$pkgname-oneshot.timer "${pkgdir}"/usr/lib/systemd/user/$pkgname-oneshot.timer
  install -Dm644 contrib/systemd/$pkgname-oneshot@.service "${pkgdir}"/usr/lib/systemd/user/$pkgname-oneshot@.service
  install -Dm644 contrib/systemd/$pkgname-oneshot@.timer "${pkgdir}"/usr/lib/systemd/user/$pkgname-oneshot@.timer
}
